﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Doctorwork.Controls
{
	/// <summary>
	/// 按照步骤 1a 或 1b 操作，然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
	///
	/// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
	/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
	/// 元素中: 
	///
	///     xmlns:MyNamespace="clr-namespace:Doctorwork.Controls.Themes"
	///
	///
	/// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
	/// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
	/// 元素中: 
	///
	///     xmlns:MyNamespace="clr-namespace:Doctorwork.Controls.Themes;assembly=Doctorwork.Controls.Themes"
	///
	/// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用，
	/// 并重新生成以避免编译错误: 
	///
	///     在解决方案资源管理器中右击目标项目，然后依次单击
	///     “添加引用”->“项目”->[浏览查找并选择此项目]
	///
	///
	/// 步骤 2)
	/// 继续操作并在 XAML 文件中使用控件。
	///
	///     <MyNamespace:Controls/>
	///
	/// </summary>
	public class ElButton : Button
	{

		static ElButton()
		{
			DefaultStyleKeyProperty.OverrideMetadata(typeof(ElButton), new FrameworkPropertyMetadata(typeof(ElButton)));
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
		}

		public ElButton()
		{
		}

		public CornerRadius Radius
		{
			get { return (CornerRadius)GetValue(RadiusProperty); }
			set
			{
				SetValue(RadiusProperty, value);
			}
		}
		public static readonly DependencyProperty RadiusProperty =
			DependencyProperty.Register("RadiusProperty", typeof(CornerRadius), typeof(ElButton), new PropertyMetadata(new CornerRadius(4)));

		/// <summary>
		/// 图标Path
		/// </summary>
		public string Icon
		{
			get { return (string)GetValue(IconProperty); }
			set { SetValue(IconProperty, value); }
		}

		// Using a DependencyProperty as the backing store for Icon.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty IconProperty =
			DependencyProperty.Register("Icon", typeof(string), typeof(ElButton), new PropertyMetadata(string.Empty));

		public static readonly DependencyProperty IconMarginProperty = DependencyProperty.Register(
			"IconMargin", typeof(Thickness), typeof(ElButton), new PropertyMetadata(new Thickness(0, 0, 0, 0)));
		/// <summary>
		/// 字体图标间距
		/// </summary>
		public Thickness IconMargin
		{
			get { return (Thickness)GetValue(IconMarginProperty); }
			set { SetValue(IconMarginProperty, value); }
		}


		/// <summary>
		/// 图标高度
		/// </summary>
		public double IconHeight
		{
			get { return (double)GetValue(IconHeightProperty); }
			set { SetValue(IconHeightProperty, value); }
		}

		public static readonly DependencyProperty IconHeightProperty =
			DependencyProperty.Register("IconHeight", typeof(double), typeof(ElButton), new PropertyMetadata(16.0));


		/// <summary>
		/// 图标宽度
		/// </summary>
		public double IconWidth
		{
			get { return (double)GetValue(IconWidthProperty); }
			set { SetValue(IconWidthProperty, value); }
		}

		public static readonly DependencyProperty IconWidthProperty =
			DependencyProperty.Register("IconWidth", typeof(double), typeof(ElButton), new PropertyMetadata(16.0));



		public ControlSize Size
		{
			get { return (ControlSize)GetValue(SizeProperty); }
			set { SetValue(SizeProperty, value); }
		}

		/// <summary>
		/// 尺寸，可选值medium / small / mini
		/// </summary>
		public static readonly DependencyProperty SizeProperty =
			DependencyProperty.Register("Size", typeof(ControlSize), typeof(ElButton), new PropertyMetadata(ControlSize.medium, OnButtonSizeChanged));

		private static void OnButtonSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			if (d is ElButton)
			{
				ElButton button = d as ElButton;
				ControlSize size =(ControlSize)e.NewValue;
				switch(size)
				{
					case ControlSize.normal:
						button.Height = 40;
						break;
					case ControlSize.medium:
						button.Height = 36;
						break;
					case ControlSize.small:
						button.Height = 32;
						break;
					case ControlSize.mini:
						button.Height = 28;
						break;
				}
			}
		}
	}
}
